<?php

class RankController extends BaseController
{
    public function init()
    {
        parent::init();
        $this->req = $this->getRequest();
    }

    /**
     * 竞猜排行榜
     */
    public function indexAction()
    {
        /**
         * 默认获取总排行数据
         */
        $req = array();
        $req['uid'] = $this->user_id;
        $req['type'] = \Orm\UserAccount\UserAccountClass::SCORE_TYPE_TOTAL;
        $req['offset'] = 0;
        $req['size'] = 200;
        $rest = new \Base\Rest();
        $res = $rest->get('Score','', $req);
        if ($res->isSuccess()) {
            $scoreList = $res->getResponse();
        }else{
            $scoreList = array();
        }
        $time = date('Y-m-d',time());
        if($time >='2018-07-10'){
            $this->view->type = 1;
        }elseif ($time >='2018-07-04'){
            $this->view->type = 2;
        }elseif ($time >='2018-06-28'){
            $this->view->type = 3;
        }elseif ($time >='2018-06-21'){
            $this->view->type = 4;
        }else{
            $this->view->type = 5;
        }
        $this->view->score_list = !empty($scoreList) ? $scoreList['list'] : array();
        $this->view->title = '竞猜排行榜';
    }

    /**
     * ajax请求加载排行信息
     */
    public function getRankAction(){
        $req['type'] = isset($_GET['type']) && $_GET['type'] != '' ? $_GET['type'] :  \Orm\UserAccount\UserAccountClass::SCORE_TYPE_TOTAL;
        $req['offset'] = isset($_GET['offset']) && $_GET['offset'] != '' ? $_GET['offset'] : 0;
        $req['size'] = isset($_GET['size']) && $_GET['size'] != '' ? $_GET['size'] : 0;
        if($req['type'] == \Orm\UserAccount\UserAccountClass::SCORE_TYPE_WEEK){
            $req['week_type'] = isset($_GET['week_type']) && $_GET['week_type'] != '' ? $_GET['week_type'] : 1;
        }
        $rest = new \Base\Rest();
        $res = $rest->get('Score','', $req);
        if ($res->isSuccess()) {
            $response = $res->getResponse();
            Response::Success($response);
        }else{
            Response::Error(201, $res->getErrorMessage());
        }

    }
}